package com.example.arithmeticleetcode.leetcode.august;

/**
 * @program: arithmetic-leetcode
 * @description:
 * @author: FangZhen
 * @create: 2020-08-03 14:14
 **/
public class Demo01 {

    public static void main(String[] args) {
        int[] arr1 = {3,0,1,1,9,7};
        System.out.println(countGoodTriplets(arr1, 7, 2, 3)); //4   [(3,0,1), (3,0,1), (3,1,1), (0,1,1)]
        int[] arr2 = {1,1,2,2,3};
        System.out.println(countGoodTriplets(arr1, 0, 0, 1)); //0
        int[] arr3 = {7,3,7,3,12,1,12,2,3};
        System.out.println(countGoodTriplets(arr3, 5, 8, 1)); //12
    }

    public static int countGoodTriplets(int[] arr, int a, int b, int c) {
        int len = arr.length;
        int count = 0;
        for (int i = 0, len1 = len - 2; i < len1; ++i) {
            for (int j = i + 1, len2 = len - 1; j < len2; ++j) {
                for (int k = j + 1, len3 = len; k < len3; ++k) {
                    if (Math.abs(arr[i] - arr[j]) <= a && Math.abs(arr[j] - arr[k]) <= b && Math.abs(arr[i] - arr[k]) <= c ) {
                        System.out.println(arr[i] + "===" + arr[j] + "====" + arr[k]);
                        count ++;
                    }
                }
            }
        }
        return count;
    }
}
